//
//  Simple.m
//  PezMonkey
//
//  Created by Spence DiNicolantonio on 12/22/09.
//  Copyright 2009 Necrosoft. All rights reserved.
//

#import "Simple.h"


@implementation Simple

- (NSString *)demoName {
	return @"Simple";
}

- (void)start {
	// create space
	self.space = [PMSpace spaceWithGravity:PMVectMake(0, -1)];
	[space setSubSteps:3];
	[space setIterations:3];
	[space setActiveHashSize:1000 cellDimension:30];
	[space setStaticHashSize:1000 cellDimension:30];
	
	// create a shared static body
	PMBody *staticBody = [PMBody staticBody];
	
	// create temp shape reference
	PMShape *shape;
	
	
	// define boundary segment width 
	// (needs to be thick to avoid penetration at high velocities)
	PMFloat width = 30;
	
	// create left screen boundary
	shape = [PMSegmentShape segmentShapeWithBody:staticBody
										   start:PMVectMake(-320 - width/2, -240)
											 end:PMVectMake(-320 - width/2, 240)
										   width:width];
	[shape setElasticity:1.0];
	[shape setFriction:1.0];
	[shape setLayers:PMLayerMaskNotGrabbable];
	[space addStaticShape:shape];
	
	// create right screen boundary
	shape = [PMSegmentShape segmentShapeWithBody:staticBody
										   start:PMVectMake(320 + width/2, -240) 
											 end:PMVectMake(320 + width/2, 240)
										   width:width];
	[shape setElasticity:1.0];
	[shape setFriction:1.0];
	[shape setLayers:PMLayerMaskNotGrabbable];
	[space addStaticShape:shape];
	
	// create bottom screen boundary
	shape = [PMSegmentShape segmentShapeWithBody:staticBody
										   start:PMVectMake(-320, -240 - width/2) 
											 end:PMVectMake(320, -240 - width/2)
										   width:width];
	[shape setElasticity:1.0];
	[shape setFriction:1.0];
	[shape setLayers:PMLayerMaskNotGrabbable];
	[space addStaticShape:shape];
	
	
	// define ball attributes
	PMFloat radius = 15.0;
	PMFloat mass = 10.0;
	PMFloat moment = PMMomentForCircle(mass, 0, radius, PMVectZero);
	
	// create ball body
	PMBody *ballBody = [PMBody bodyWithMass:mass 
									 moment:moment];
	[space addBody:ballBody];
	
	// create ball collision shape
	PMShape *ballShape = [PMCircleShape circleShapeWithBody:ballBody 
													 radius:radius];
	[ballShape setFriction:0.6];
	[ballShape setElasticity:0.6];
	[space addShape:ballShape];
}


@end
